//
//  HomepageViewController.m
//  UI_HLJ_Frame
//
//  Created by  毕宏伟 on 15/6/29.
//  Copyright (c) 2015年 毕宏伟. All rights reserved.
//

#import "HomepageViewController.h"
#import "AFNetworking.h"
#import "lunboModel.h"
#define WIDTH self.view.frame.size.width
#define HEIGHT self.view.frame.size.height
#import "UIImageView+WebCache.h"
#import "buttonModel.h"
#import "discountCell.h"
#import "discountModel.h"
#import "merchantModel.h"
#import "LabelCell.h"
#import "labelModel.h"
#import "goodsrecCell.h"
#import "homePageCellModel.h"
#import "homePagecellmerchanModel.h"
#import "MJRefresh.h"
#import "UIButton+WebCache.h"
#import "leftButtonDetailViewController.h"
#import "midButtonViewController.h"
#import "rightBtnViewController.h"
#import "MBProgressHUD.h"
#import "productionViewController.h"
#import "disCountdetailViewController.h"
#import "labelbtnViewController.h"
#import "SearchBarViewController.h"
#import "Myplayer.h"
#import "hunlijiWebViewController.h"
@interface HomepageViewController ()<UITableViewDataSource,UITableViewDelegate,UISearchBarDelegate>

//设置headerview
@property(nonatomic,retain)UIView *headerView;

//设置scrollview
@property(nonatomic,retain)UIScrollView *scrollview;

@property(nonatomic,retain)NSMutableArray *picArr;

@property(nonatomic,retain)NSMutableArray *lunboPicArr;

@property(nonatomic,retain)NSMutableArray *buttonArr;

@property(nonatomic,retain)NSMutableArray *btnpicArr;

@property(nonatomic,retain)UITableView *tableview;

@property(nonatomic,retain)UIView *titleView;

@property(nonatomic,retain)NSMutableArray *discountArr;

@property(nonatomic,retain)NSMutableArray *merchantArr;

@property(nonatomic,retain)NSMutableArray *homecellArr;

@property(nonatomic,retain)NSMutableArray *homemerchanArr;

@property(nonatomic,retain)UIButton *leftButton;

@property(nonatomic,retain)UIButton *midButton;

@property(nonatomic,retain)UIButton *rightButton;

@property(nonatomic,retain)UIButton *topButton;

@property(nonatomic,retain)MBProgressHUD *hud;
//设置刷新当前页数
@property(nonatomic,assign)NSInteger pageCount;

@property(nonatomic,retain)UIButton *playButton;


@property (nonatomic,retain)UICollectionView *mycollview;

@end

@implementation HomepageViewController

-(void)dealloc
{
    [_scrollview release];
    [_tableview release];
    [_btnpicArr release];
    [_merchantArr release];
    [_picArr release];
    [_lunboPicArr release];
    [_homecellArr release];
    [_homemerchanArr release];
    [_mycollview release];
    [super dealloc];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    self.title = @"首页";
    
    self.navigationController.navigationBar.tintColor =[UIColor colorWithRed:1.000 green:0.452 blue:0.871 alpha:1.000];

    self.tabBarItem.title = @"推荐";
    
    self.navigationItem.leftBarButtonItem =[[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"戒指"] style:UIBarButtonItemStylePlain target:self action:@selector(leftClick:)];
    
    self.navigationController.navigationBar.translucent =NO;
    self.navigationController.navigationBar.barTintColor =[UIColor whiteColor];
    
    self.navigationItem.rightBarButtonItem =[[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"查找"] style:UIBarButtonItemStylePlain target:self action:@selector(click:)];
    
    
    
    //创建topbutton
   
    
    
    [self createData];
    [[Myplayer sharePlayer] playMusicWithURL:@"http://sc.111ttt.com/up/mp3/272570/7E995357EE42EACCE4897B737BC17390.mp3"];
    
    [self createView];
    
    
    self.pageCount = 2;
    
    self.hud = [MBProgressHUD showHUDAddedTo:self.tableview animated:YES];
    self.hud.labelText =@"loading...";
    
    [self.tableview addHeaderWithTarget:self action:@selector(headerRereshing)];
    [self.tableview addFooterWithTarget:self action:@selector(footerRereshing)];
    
    [self createTopButton];
    
}

-(void)leftClick:(UIButton *)button
{
    hunlijiWebViewController *hunliVC =[[hunlijiWebViewController alloc]init];
    [self.navigationController pushViewController:hunliVC animated:YES];
    [hunliVC release];
}

//放大镜查找方法
- (void)click:(UIButton *)button
{
    SearchBarViewController *searchVC =[[SearchBarViewController alloc]init];
    [self.navigationController pushViewController:searchVC animated:YES];
    [searchVC release];
    
    //设置搜索textField
//    UITextField *searchTextField = [[UITextField alloc]init];
//    searchVC.searchBar = [[UISearchBar alloc]init];
//    searchVC.searchBar.frame = CGRectMake(0, 0, 0, 0);
//    searchVC.searchBar.layer.borderColor = [UIColor grayColor].CGColor;
//    //    self.searchBar.backgroundColor = [UIColor greenColor];
//    searchVC.searchBar.placeholder = @"请输入关键字";
//    
//    //找到searchBar上的textfield
//    searchTextField = [[[searchVC.searchBar.subviews firstObject] subviews] lastObject];
//    //设置背景颜色
//    searchTextField.backgroundColor = [UIColor colorWithRed:60/255.0 green:156/255.0 blue:170/255.0 alpha:1];;
//    //更改占位符字体颜色
//    [searchTextField setValue:[UIColor whiteColor] forKeyPath:@"_placeholderLabel.textColor"];
//    searchTextField.layer.cornerRadius = 15;
//    //去掉放大镜
//    [searchTextField setLeftViewMode:UITextFieldViewModeNever];
//    //
//    searchVC.searchBar.delegate = self;
//    searchVC.navigationItem.titleView = searchVC.searchBar;
}



#pragma mark 创建topbuttonview

- (void)createTopButton
{
    
        
        self.topButton = [UIButton buttonWithType:UIButtonTypeSystem];
        [self.topButton setTitle:@"Top" forState:UIControlStateNormal];
        self.topButton.frame = CGRectMake(0.85 * WIDTH, 0.65 * HEIGHT, 36, 36);
        self.topButton.backgroundColor = [UIColor colorWithRed:1.000 green:0.404 blue:0.651 alpha:1.000];
        [self.topButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        self.topButton.clipsToBounds = YES;
        self.topButton.alpha = 0.8;
        self.topButton.layer.cornerRadius = 18;
        [self.topButton addTarget:self action:@selector(moveToTop) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:self.topButton];
    
    
    
    self.playButton =[UIButton buttonWithType:UIButtonTypeSystem];
   
    [self.playButton setTitle:@"play" forState:UIControlStateNormal];
    self.playButton.frame =CGRectMake(0.05*WIDTH, 0.65 *HEIGHT, 36, 36);

    self.playButton.backgroundColor = [UIColor colorWithRed:1.000 green:0.404 blue:0.651 alpha:1.000];
    [self.playButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    self.playButton.clipsToBounds = YES;
    self.playButton.alpha = 0.8;
    self.playButton.layer.cornerRadius = 18;
    [self.playButton addTarget:self action:@selector(playmusic:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.playButton];
}


- (void)playmusic:(UIButton *)button
{
    [[Myplayer sharePlayer] playMusicWithURL:@"http://sc.111ttt.com/up/mp3/272570/7E995357EE42EACCE4897B737BC17390.mp3"];
}

//添加尾部加载方法
- (void)footerRereshing
{
    NSString *url = [NSString stringWithFormat:@"http://hunliji.com/v2/api/app/works?page=%ld&per_page=20&commodity_type=1",self.pageCount];
    AFHTTPRequestOperationManager *homecellmanager = [AFHTTPRequestOperationManager manager];
    [homecellmanager GET:url parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        
        NSDictionary *dic =responseObject;
        
        NSArray *arr = dic[@"works"];
        
        for (NSDictionary *worksdic in arr) {
            
            NSDictionary *tempdic = [worksdic objectForKey:@"merchant"];
            
            homePagecellmerchanModel *homemerchan = [[homePagecellmerchanModel alloc]init];
            
            [homemerchan setValuesForKeysWithDictionary:tempdic];
            
            [self.homemerchanArr addObject:homemerchan];
            
            homePageCellModel *homecell = [[homePageCellModel alloc]init];
            
            [homecell setValuesForKeysWithDictionary:worksdic];
            
            [self.homecellArr addObject:homecell];
            
            [homecell release];
            
        }
        
        [self.tableview reloadData];
        [self.tableview footerEndRefreshing];
        self.pageCount++;
        

    
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
        
    }];
}

//添加头步刷新方法
-(void)headerRereshing
{
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    [manager GET:@"http://hunliji.com/v1/api/app/posters.json?app_version=5.5.0&cid=0&device=1" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        [self.lunboPicArr removeAllObjects];
        [self.btnpicArr removeAllObjects];
        [self.buttonArr removeAllObjects];
        
        NSDictionary *dic = responseObject;
        
        NSArray *sitesArr = dic[@"sites"];
        
        NSArray *postersArr = sitesArr[0][@"posters"];
        NSArray *btnArr = sitesArr[1][@"posters"];
        for (NSDictionary *postersDic in postersArr) {
            
            lunboModel *lunbo = [[lunboModel alloc]init];
            [lunbo setValuesForKeysWithDictionary:postersDic];
            
            [self.picArr addObject:lunbo];
            [self.lunboPicArr addObject:lunbo.image_path];
            
            [lunbo release];
            
        }
        for (NSDictionary *btntempdic in btnArr) {
            
            buttonModel *btn = [[buttonModel alloc]init];
            
            [btn setValuesForKeysWithDictionary:btntempdic];
            
            [self.btnpicArr addObject:btn];
            
            [self.buttonArr addObject:btn.image_path];
            
            [btn release];
        }
        
        NSString *lastStr = [self.lunboPicArr lastObject];
        [self.lunboPicArr insertObject:lastStr atIndex:0];
        NSString *firstStr = self.lunboPicArr[1];
        [self.lunboPicArr insertObject:firstStr atIndex:self.lunboPicArr.count];
        
        //给三张图片赋值
        [self.leftButton sd_setImageWithURL:[NSURL URLWithString:self.buttonArr[0]] forState:UIControlStateNormal];
        [self.midButton sd_setImageWithURL:[NSURL URLWithString:self.buttonArr[1]] forState:UIControlStateNormal];
        [self.rightButton sd_setImageWithURL:[NSURL URLWithString:self.buttonArr[2]] forState:UIControlStateNormal];
//        NSLog(@"数据解析成功");
        [self loadScrollView];
        
        [self.view reloadInputViews];
        
        [self.tableview headerEndRefreshing];
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
        
    }];
    
    
    AFHTTPRequestOperationManager *homecellmanager = [AFHTTPRequestOperationManager manager];
    [homecellmanager GET:@"http://hunliji.com/v2/api/app/works?page=1&per_page=20&commodity_type=1&first_query_time=2015-07-01T02%3A08%3A58Z" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        [self.homecellArr removeAllObjects];
        //第二次请求准备刷新到第二页
        self.pageCount = 2;
        
        NSDictionary *dic =responseObject;
        
        NSArray *arr = dic[@"works"];
        
        for (NSDictionary *worksdic in arr) {
            
            NSDictionary *tempdic = [worksdic objectForKey:@"merchant"];
            
            homePagecellmerchanModel *homemerchan = [[homePagecellmerchanModel alloc]init];
            
            [homemerchan setValuesForKeysWithDictionary:tempdic];
            
            [self.homemerchanArr addObject:homemerchan];
            
            homePageCellModel *homecell = [[homePageCellModel alloc]init];
            
            [homecell setValuesForKeysWithDictionary:worksdic];
            
            [self.homecellArr addObject:homecell];
            
            [homecell release];
            
        }
        
        [self.tableview reloadData];
        
        [self.tableview headerEndRefreshing];
    
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
        
    }];

}


- (void)createData
{
    self.picArr = [NSMutableArray array];
    self.lunboPicArr = [NSMutableArray array];
    self.buttonArr = [NSMutableArray array];
    self.btnpicArr = [NSMutableArray array];
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    [manager GET:@"http://hunliji.com/v1/api/app/posters.json?app_version=5.5.0&cid=0&device=1" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        NSDictionary *dic = responseObject;
        
        NSArray *sitesArr = dic[@"sites"];
        
        NSArray *postersArr = sitesArr[0][@"posters"];
        NSArray *btnArr = sitesArr[1][@"posters"];
        for (NSDictionary *postersDic in postersArr) {
            
            lunboModel *lunbo = [[lunboModel alloc]init];
            [lunbo setValuesForKeysWithDictionary:postersDic];
            
            [self.picArr addObject:lunbo];
            [self.lunboPicArr addObject:lunbo.image_path];
        
            [lunbo release];
            
        }
        for (NSDictionary *btntempdic in btnArr) {
            
            buttonModel *btn = [[buttonModel alloc]init];
            
            [btn setValuesForKeysWithDictionary:btntempdic];
            
            [self.btnpicArr addObject:btn];
           
            [self.buttonArr addObject:btn.image_path];
            
            [btn release];
        }
        
        NSString *lastStr = [self.lunboPicArr lastObject];
        [self.lunboPicArr insertObject:lastStr atIndex:0];
        NSString *firstStr = self.lunboPicArr[1];
        [self.lunboPicArr insertObject:firstStr atIndex:self.lunboPicArr.count];
#pragma mark 给第二部分的三张图片赋值
        //给三张图片赋值
//        [self.leftButton sd_setImageWithURL:[NSURL URLWithString:self.buttonArr[0]] forState:UIControlStateNormal placeholderImage:[UIImage imageNamed:@"Category2"] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
//            
//            
//        }];
        
        //button图片赋值操作.
        [self.leftButton sd_setImageWithURL:[NSURL URLWithString:self.buttonArr[0]] forState:UIControlStateNormal];
        [self.midButton sd_setImageWithURL:[NSURL URLWithString:self.buttonArr[1]] forState:UIControlStateNormal];
        [self.rightButton sd_setImageWithURL:[NSURL URLWithString:self.buttonArr[2]] forState:UIControlStateNormal];
//         NSLog(@"数据解析成功");
        [self loadScrollView];

        [self.view reloadInputViews];
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
        
    }];
    
    
    self.homecellArr = [NSMutableArray array];
    self.homemerchanArr = [NSMutableArray array];
    AFHTTPRequestOperationManager *homecellmanager = [AFHTTPRequestOperationManager manager];
    [homecellmanager GET:@"http://hunliji.com/v2/api/app/works?page=1&per_page=20&commodity_type=1&first_query_time=2015-07-01T02%3A08%3A58Z" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        
        NSDictionary *dic =responseObject;
        
        NSArray *arr = dic[@"works"];
        
        for (NSDictionary *worksdic in arr) {
            
            NSDictionary *tempdic = [worksdic objectForKey:@"merchant"];
            
            homePagecellmerchanModel *homemerchan = [[homePagecellmerchanModel alloc]init];
            
            [homemerchan setValuesForKeysWithDictionary:tempdic];
            
            [self.homemerchanArr addObject:homemerchan];
            

            homePageCellModel *homecell = [[homePageCellModel alloc]init];
            
            [homecell setValuesForKeysWithDictionary:worksdic];
            
            [self.homecellArr addObject:homecell];
            
            [homecell release];
            
        }
        
        [self.tableview reloadData];
//        NSLog(@"数据解析成功");
        [self.view reloadInputViews];
        [self.hud hide:YES afterDelay:2.0];
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
        
    }];
    
    
    

}


#pragma mark 创建视图
- (void)createView
{
    
    
    
    
    
    //创建headerView
    self.headerView =[[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 350)];
    self.headerView.backgroundColor = [UIColor whiteColor];
    
    [self.view addSubview:self.headerView];
    
    //创建一个scrollview放在headerview上
    self.scrollview = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 200)];
    self.scrollview.backgroundColor = [UIColor whiteColor];
    [self.headerView addSubview:self.scrollview];
    [_scrollview release];
    
    
    self.scrollview.pagingEnabled =YES;
    self.scrollview.showsHorizontalScrollIndicator = NO;
    //设置初始位置
    self.scrollview.tag = 1314;
    [self.scrollview alwaysBounceHorizontal];
    [NSTimer scheduledTimerWithTimeInterval:5 target:self selector:@selector(timer) userInfo:nil repeats:YES];
    
    
    //创建第二部分三张图片
    
    self.leftButton =[UIButton buttonWithType:UIButtonTypeCustom];
    self.leftButton.frame = CGRectMake(WIDTH / 25, 210, WIDTH / 3.75, 130);
    self.leftButton.backgroundColor = [UIColor whiteColor];
    self.leftButton.tag =100;
    [self.headerView addSubview:self.leftButton];
    [self.leftButton addTarget:self action:@selector(leftButtonclick:) forControlEvents:UIControlEventTouchUpInside];

    self.midButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.midButton.frame = CGRectMake(WIDTH / 2.75, 210, WIDTH / 3.75, 130);
    self.midButton.backgroundColor = [UIColor whiteColor];
    self.midButton.tag =101;
    [self.headerView addSubview:self.midButton];
    [self.midButton addTarget:self action:@selector(midButtonclick:) forControlEvents:UIControlEventTouchUpInside];

    self.rightButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.rightButton.frame = CGRectMake(WIDTH / 1.45, 210, WIDTH / 3.75, 130);
    self.rightButton.backgroundColor = [UIColor whiteColor];
    [self.headerView addSubview:self.rightButton];
    self.rightButton.tag = 102;
    [self.rightButton addTarget:self action:@selector(rightButtonclick:) forControlEvents:UIControlEventTouchUpInside];
    
    
    
#pragma mark 创建tableview
    
    self.tableview = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, self.view.frame.size.height-64) style:UITableViewStylePlain];
    
    self.tableview.backgroundColor = [UIColor whiteColor];
                                      
    [self.view addSubview:self.tableview];
    [_tableview release];
    
    
    //设置tableview代理人
    self.tableview.delegate = self;
    self.tableview.dataSource =self;
    self.tableview.tableHeaderView = self.headerView;
    
    
    
    

}


#pragma mark 创建topbutton方法

- (void)moveToTop
{
    self.tableview.contentOffset = CGPointMake(0, 0);
}



#pragma mark 第二部分三个button的点击方法
- (void)leftButtonclick:(UIButton *)button
{
    
    leftButtonDetailViewController *leftVC = [[leftButtonDetailViewController alloc]init];
    buttonModel *btn = self.btnpicArr[button.tag - 100];
    leftVC.btnUrl =btn.target_url;
    [self.navigationController pushViewController:leftVC animated:YES];
        [leftVC release];
}

- (void)midButtonclick:(UIButton *)button
{
    midButtonViewController *midVC = [[midButtonViewController alloc]init];
    buttonModel *btn = self.btnpicArr[button.tag-100];
    midVC.midUrl =btn.target_url;
    [self.navigationController pushViewController:midVC animated:YES];
    [midVC release];
}



- (void)rightButtonclick:(UIButton *)button
{
    rightBtnViewController *rightVC = [[rightBtnViewController alloc]init];
    buttonModel *btn = self.btnpicArr[button.tag-100];
    rightVC.rightUrl =btn.target_url;
    [self.navigationController pushViewController:rightVC animated:YES];
    [rightVC release];
    
}

#pragma mark scrollView的图片加载
- (void)loadScrollView {
    self.scrollview.contentSize =CGSizeMake(self.lunboPicArr.count*WIDTH, 0);
    //self.page.numberOfPages = self.lunboPicArr.count-2;
    
    self.scrollview.contentOffset = CGPointMake(WIDTH, 0);
    for (NSInteger i = 0; i < self.lunboPicArr.count; i++) {
        UIImageView *imageView = [[UIImageView alloc] init];
        [imageView sd_setImageWithURL:[NSURL URLWithString:self.lunboPicArr[i]]];
        imageView.frame = CGRectMake(WIDTH * i, 0, WIDTH, 200);
        [self.scrollview addSubview:imageView];
        [imageView release];
    }
}





// 定时器 实现轮播图循环滚动
- (void)timer {
    CGPoint point = CGPointMake(self.scrollview.contentOffset.x + WIDTH, 0);
    [self.scrollview setContentOffset:point animated:YES];
    //     图片自动滚动后判断偏移量,如果是最后一张图就直接设置偏移量到第二张图.实现无限滚动
    if (self.scrollview.contentOffset.x == (self.lunboPicArr.count-1)* WIDTH) {
        self.scrollview.contentOffset = CGPointMake(WIDTH, 0);
    }
   }






#pragma mark 实现tableview的协议方法
//设置返回cell的数量
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section ==0) {
        return 1;
    }
    else if (section ==1)
    {
        return 1;
    }
    else
    {
        return self.homecellArr.count;
    }
}

//设置行高
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section ==0) {
        return 260;
    }
    else if (indexPath.section ==1)
    {
        return 250;
    }
    else
    {
        return 280;
    }
}



//设置区数量
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 3;
}
#pragma mark cell重用赋值
//cell赋值
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section ==0) {
        
        static NSString *reuse = @"reuse";
        discountCell *cell = [tableView dequeueReusableCellWithIdentifier:reuse];
        if (!cell) {
            cell = [[[discountCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:reuse]autorelease];
            
                     }
        
        
        return cell;
    }
    else if (indexPath.section ==1)
    {
        static NSString *reuse1 = @"reuse1";
        LabelCell *cell = [tableView dequeueReusableCellWithIdentifier:reuse1];
        if (!cell) {
            cell = [[[LabelCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:reuse1]autorelease];
             [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
            
        }
        
        
        return cell;
    }
    
    else
    {
        static NSString *reuse2 = @"reuse2";
        goodsrecCell *cell = [tableView dequeueReusableCellWithIdentifier:reuse2];
        if (!cell) {
            cell = [[[goodsrecCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:reuse2]autorelease];
            [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
           
        }
        
        
        homePageCellModel *home = self.homecellArr[indexPath.row];
        homePagecellmerchanModel *homemer =self.homemerchanArr[indexPath.row];
        cell.smalltitleLabel.text = homemer.name;
        cell.bigtitleLbael.text = home.title;
        [cell.bigImage sd_setImageWithURL:[NSURL URLWithString:home.cover_path] placeholderImage:[UIImage imageNamed:@"占位图"]];
        cell.collectLabel.text =[home.collectors_count stringValue];
        
       
       
        return cell;
    }
}

#pragma mark 实现tableview的点击方法

//点击方法
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    if (indexPath.section==2) {
        
        productionViewController *proVC = [[productionViewController alloc]init];
        
        homePageCellModel *cellmo = self.homecellArr[indexPath.row];
        homePagecellmerchanModel *home = self.homemerchanArr[indexPath.row];
        proVC.name1 = home.name;
        proVC.bid =cellmo.bid;
        [self.navigationController pushViewController:proVC animated:YES];
        [proVC release];
        
        
    }
    
}




//返回标题
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    return @"123";
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    if (section ==0) {
        
        self.titleView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 30)];
        self.titleView.backgroundColor = [UIColor colorWithRed:1.000 green:0.404 blue:0.651 alpha:1.000];
        UILabel *leftLabel =[[UILabel alloc]initWithFrame:CGRectMake(10,1,120, 30)];
        leftLabel.text = @"超值折扣";
        
        [self.titleView addSubview:leftLabel];
        UIButton *moreButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [moreButton setTitle:@"查看详情 ＞" forState:UIControlStateNormal];
        [moreButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        moreButton.frame = CGRectMake(WIDTH * 1.4 / 2, 5, 100, 20);
        [self.titleView addSubview:moreButton];
        [moreButton addTarget:self action:@selector(morebtn:) forControlEvents:UIControlEventTouchUpInside];
        
        [_titleView release];
        return self.titleView;

    }
    else if (section==1)
    {
        self.titleView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 30)];
        self.titleView.backgroundColor = [UIColor colorWithRed:1.000 green:0.404 blue:0.651 alpha:1.000];
        
        UILabel *leftLabel =[[UILabel alloc]initWithFrame:CGRectMake(10,1,120, 30)];
        leftLabel.text = @"标签推荐";
        
        [self.titleView addSubview:leftLabel];
        UIButton *moreButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [moreButton setTitle:@" 感兴趣 ＞" forState:UIControlStateNormal];
        moreButton.frame = CGRectMake(WIDTH * 1.4 / 2, 5, 100, 20);
        [self.titleView addSubview:moreButton];
        [moreButton addTarget:self action:@selector(labelBtn:) forControlEvents:UIControlEventTouchUpInside];
        
        [_titleView release];
        return self.titleView;
    }
    
   else if (section==2)
   {
       self.titleView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 30)];
       self.titleView.backgroundColor = [UIColor colorWithRed:1.000 green:0.404 blue:0.651 alpha:1.000];
       UILabel *leftLabel =[[UILabel alloc]initWithFrame:CGRectMake(10,1,120, 30)];
       leftLabel.text = @"推荐作品";
       
       [self.titleView addSubview:leftLabel];
       UIButton *moreButton = [UIButton buttonWithType:UIButtonTypeCustom];
//       [moreButton setTitle:@"更多>" forState:UIControlStateNormal];
       moreButton.frame = CGRectMake(280, 10, 50, 10);
       [self.titleView addSubview:moreButton];
       
       [_titleView release];
       return self.titleView;
       
   }
    
    else
    {
        return nil;
    }
}

//标签的补救方法

- (void)labelBtn:(UIButton *)button
{
    labelbtnViewController *labVC = [[labelbtnViewController alloc]init];
    [self.navigationController pushViewController:labVC animated:YES];
    [labVC release];
    
}

//查看详情的button方法
- (void)morebtn:(UIButton *)button
{
    disCountdetailViewController *disVC =[[disCountdetailViewController alloc]init];
    [self.navigationController pushViewController:disVC animated:YES];
    [disVC release];
    
}
    
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
